package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TravelCommend;
import cn.wolfcode.trip.base.mapper.TravelCommendMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.TravelCommendQueryObject;
import cn.wolfcode.trip.base.service.ITravelCommendService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TravelCommendServiceImpl implements ITravelCommendService {


    @Autowired
    private TravelCommendMapper travelCommendMapper;


    public PageInfo<?> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        return new PageInfo<>(travelCommendMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(TravelCommend entity) {
        if (entity.getId()!=null){
            travelCommendMapper.updateByPrimaryKey(entity);
        }else {
            travelCommendMapper.insert(entity);
        }
    }

    @Override
    public PageInfo<?> queryForApp(TravelCommendQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        return new PageInfo<>(travelCommendMapper.selectForAppList(qo));
    }
}
